/*
	会员等级 列表
*/
var adminLoginedInfo = Cookies.getJSON('kplus_ad_logined_info');

//dom
$(function(){
	layui.use(['layer', 'form', 'table'], function(){
		var layer = layui.layer, form = layui.form, table = layui.table;
		//ajaxData
		var ajaxData = { aId: adminLoginedInfo.aId, aToken: adminLoginedInfo.aToken };

		function getUserVipLevelChangeData(){
			/*
				获取用户vip等级变动信息（未处理）
				接口方法 get
			*/
			var loadIndex = layer.load(1, { shade: [0.5, '#000'] });
			var _ajaxData = $.extend(ajaxData, {'status': '0'}); // 0 表示处理

			$.ajax({
				url: BASE_SERVICEURL + URlS.userVipChangeDeal,
				type: 'GET',
				data: _ajaxData,
				success: function(responseData){
					var code = responseData.msg.code;
					if(code == 200){
						//console.log(responseData)
						createTable(responseData);
						layer.close(loadIndex)
					}else if(code == 2005){
						//登录失效
						layer.msg('登录失效，请重新登陆后重试', {time: 2000, end: function(){
							parent.layer.close(layer.index);
                        	window.parent.location.reload();
						}});
					}else if(code == 2002){
						layer.msg('接口缺少必要参数，请确认数据均以填写后重试！', {time: 2000});
						layer.close(loadIndex)
					}
				},
				error: function(responseData){
					layer.msg(MESSAGES.service_error , { time: 2000, end: function(){
                    	window.location.href = './500.html';
                    }});
				}
			})
		};

		// 构建table
		function createTable(responseData){
			//组织表格数据
			var data = responseData.data;
			var tableData = [];
			for (var i = data.length - 1; i >= 0; i--) {
				//倒叙
				tableData.push({
					ID: data[i].id,
					userId: data[i].u_id,
					uName: data[i].u_name,
					uMail: data[i].u_mail,
					level: data[i].user_leave,
					time: formatTime(data[i].format_time),
					treated_time: formatTime(data[i].treated_time),
					status_name: data[i].status_name,
					sign: data[i].sign
				})
			}
			//构建表格
			table.render({
				elem: '#tableContent',
				limit: 20, //分页
				height: 620,
				page: true,
				cols:[[ //表头
					{field: 'ID', title: '事件编号', sort: true, fixed: 'left', width:120},
					{field: 'userId', title: '用户ID', width:120},
					{field: 'uName', title: '用户名'},
					{field: 'uMail', title: '用户邮箱'} ,
					{field: 'level', title: '晋级VIP等级'} ,
					{field: 'time', title: '晋级时间', sort: true},
					{field: 'treated_time', title: '处理时间', sort: true},
					{field: 'status_name', title: '处理状态', sort: true},
					{field: 'sign', title: '备注', sort: true}
				]],
				data:tableData
			});
		}

		getUserVipLevelChangeData();
	});
})
